package net.maxupeng.asm74.segment;

import lombok.Data;
import net.maxupeng.asm74.antlr.ASM74Parser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class Segment {
    private static int counter = 0;
    private final int id;

    public ASM74Parser.ProgContext progCtx;
    public int romPage = 0;
    public int ramPage = 0;
    public int ramAddr = 0;
    public int ramSize = 0;
    public int romAddr = 0;
    public int romSize = 0;
    public final List<Integer> rom = new ArrayList<>();
    public final Map<String, Integer> romLabelOffsetMap = new HashMap<>();
    public final Map<String, Integer> ramLabelOffsetMap = new HashMap<>();

    public Segment(ASM74Parser.ProgContext progCtx) {
        this.id = counter++;
        this.progCtx = progCtx;
    }

    public void output_rom(int[] romArray) {
        for (int i = 0; i < romSize; i++) {
            romArray[romPage * 32 * 1024 + romAddr + i] = this.rom.get(i);
        }
    }

    public int getId() {
        return id;
    }

    public ASM74Parser.ProgContext getProgCtx() {
        return progCtx;
    }
}
